package com.jason.learn.springcloud.accountservice.service;

import com.jason.learn.springcloud.accountservice.dao.AccountDao;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
@RocketMQMessageListener(topic = "orderPayFlow",
        consumerGroup = "tx-consumer",
        selectorExpression = "*")
public class OrderPayConsumer  implements RocketMQListener<String>{
    private Logger logger = LoggerFactory.getLogger(OrderPayConsumer.class);

    @Autowired
    private AccountDao accountDao;

    @Override
    public void onMessage(String message) {
        logger.info("收到消息："+message);
        String[] msgs = message.split(",");
        accountDao.addMoney(Long.parseLong(msgs[0]),new BigDecimal(msgs[1]));
        logger.info(Long.parseLong(msgs[0])+"增加金额："+new BigDecimal(msgs[1]));
    }
}
